/**
 * 考試管理初始化
 */
var CompletedTest = {
    id: "CompletedTestTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};


/**
 * 初始化表格的列
 */
CompletedTest.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: '', field: 'id', visible: false, align: 'center', valign: 'middle', hidden: true},
        {title: '考试名称：', field: 'theTestName', align: 'center', valign: 'middle',},
        {title: '试卷总分：', field: 'totalScore', align: 'center', valign: 'middle',},
        {title: '通过分数：', field: 'scoresOfAdoption', align: 'center', valign: 'middle',},
        {title: '考试得分：', field: 'testScores', align: 'center', valign: 'middle',},
        {
            title: '是否通过：',
            field: 'isAdoption',
            align: 'center',
            valign: 'middle',
            formatter: function (value, row, index) {
                if(value==1){
                    return "通过";
                }else{
                    return "未通过";
                }
            }
        },
        {
            title: '考试时间：',
            field: 'timeLength',
            align: 'center',
            valign: 'middle',
            formatter: function (value, row, index) {
                return value + "分钟";
            }
        },
        {
            title: '创建时间：', field: 'createTime', align: 'center', valign: 'middle',
            formatter: function (value, row, index) {
                return value.substring(0, 10);
            }
        },
        {
            title: '考试开始时间：',
            field: 'startTime',
            align: 'center',
            valign: 'middle',
            formatter: function (value, row, index) {
                return value.substring(0, 10);
            }
        },
        {
            title: '考试结束时间：',
            field: 'endTime',
            align: 'center',
            valign: 'middle',
            formatter: function (value, row, index) {
                return value.substring(0, 10);
            }
        },
        {title: '创建人：', field: 'createPeople', align: 'center', valign: 'middle'},
        {title: '备注：', field: 'remark', align: 'center', valign: 'middle'},
        {
            title: '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ',
            field: '', align: 'center', valign: 'middle',
            formatter: function (value, row, index) {
                return '<a onclick="CompletedTest.completedTest(\'' + row.id + '\');" href="javascript:;" >查看详情</a>';
            }
        }
    ];
};
CompletedTest.completedTest = function (id) {
    $.ajax({
        url:  Feng.ctxPath +"/completedTest/to_details/",
        type: "post",
        data: {
            "theTestId": id
        },
        success: function (data) {
            window.location.href =  Feng.ctxPath +"/completedTest/to_details/";
        },
        error: function (data) {
            alert('内部故障!');
        }
    });

};


/**
 * 检查是否选中
 */
CompletedTest.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        CompletedTest.seItem = selected[0];
        return true;
    }
};

CompletedTest.getMoney = function (url) {
    window.location.href = url;
}


CompletedTest.resetSearch = function () {
    CompletedTest.search();
};

CompletedTest.formParams = function () {
    var queryData = {};
    return queryData;
}

var parseParam = function (param, key) {
    var paramStr = "";
    if (param instanceof String || param instanceof Number || param instanceof Boolean) {
        paramStr += "&" + key + "=" + param;
    } else {
        $.each(param, function (i) {
            var k = key == null ? i : key + (param instanceof Array ? "[" + i + "]" : "." + i);
            paramStr += '&' + parseParam(this, k);
        });
    }
    return paramStr.substr(1);
};

/**
 * 查询考試列表
 */
CompletedTest.search = function () {
    CompletedTest.table.refresh({query: CompletedTest.formParams()});
};

$(function () {
    var defaultColunms = CompletedTest.initColumn();
    var table = new BSTable(CompletedTest.id, "/completedTest/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(CompletedTest.formParams());
    CompletedTest.table = table.init();
    brs.innerHTML="</br></br></br></br>";
    br5s.innerHTML="</br></br></br></br></br>"
});
